<template>
    <div class="assetsManage">
        <header-btn style="margin-bottom:10px"  :btnList='tabArr' :tabIndex='Number(curTabIndex)' @changetabIndex='getCurTabIndexFn' >
            <el-select @change='changeWarehouse' style="width:150px;margin:17px 10px 0 0" size='medium'  v-model="form.wh_id" placeholder="请选择" >
                <el-option   v-for="item in myWarehouse"  :key="item.wh_id"  :label="item.wh_name" :value="item.wh_id"></el-option>
            </el-select>
        </header-btn>
        <!-- 搜索框和列表 -->
        <div class="operationBox" v-if="indexList.indexOf(curTabIndex)>-1&&(action=='table') && !assetsUpdate">
                <!-- 搜索框 -->
                <!-- <searchBox  ref="searchBox" :hideSearchBtn='curTabIndex==9' :formInline='formInline' :form='form' @search="onSubmit">
                    <el-button  type="success" v-show="curTabIndex==0"  @click="importFile">EXCEL导入</el-button>
                    <el-button style="width:100px" type="primary" v-show="curTabIndex==0"  @click="uploadFile">下载导入模板</el-button>
                    <el-button style="margin:2px 0 3px 8px" type="primary" v-show="curTabIndex==9"  @click="action='add'">创建盘点任务</el-button>
                </searchBox> -->
                <ul class="tabList">
                    <li v-for="(item,index) in tabList" :key="index" :class="{active:index == $store.state.activeIndex}" @click="tabLiChange(index,true)">
                        <el-badge :hidden="!item.number" :value="item.number" :max="99" class="badgeClass"></el-badge>
                        {{item.key}}
                    </li>
                </ul>
                <!-- v-show="curTabIndex == 0" -->
                <div style="padding:0 10px 40px;overflow:hidden;">
                    <assembly-Integration :formInline='formInline' :btnList="btnList" @search="onSubmit" @btnListClick="btnListClick" />
                    <!-- 列表 -->
                    <div class="tabel_box">
                        <lpj-table-vue :baseNum='paginationMes.per_page*(paginationMes.current_page-1)' ref="lpjTable" :tableData="tableData" :tableHeaderData="tableHeaderData[indexList.indexOf(curTabIndex)]" @linkBtnFn="linkBtnFn" @pointerClick="pointerClick" @handleSelectionChange="handleSelectionChange"></lpj-table-vue>
                    </div>
                    <!-- 页码 -->
                    <pagination v-if="paginationMes.total&&paginationMes.total>10" align="right" :paginationMes="paginationMes" @sizeChangeFn="sizeChangeFn" @currentChangeFn="currentChangeFn"></pagination>
                </div>
            
        </div>
        <!-- 新增资产 -->
        <new-Add-Asset ref="formVueBox" v-if="curTabIndex==2 || assetsUpdate" :id="assetsUpdateId" @close="assetsUpdateClose"/>
        <!-- 资产分类 -->
        <assets-class ref="assetsClass" v-if="curTabIndex==1" />
        <!-- 设置维修 -->
        <rapair-setting ref="rapairSetting" v-if="curTabIndex==8" />
         <!-- 资产盘点的新增 -->
        <asset-inventory v-if="curTabIndex==9&&action=='add'"  @actionChange='getCurTabIndexFn(curTabIndex)'/>
        <!-- 设置二维码 -->
        <qrcodeMain ref="qrcodeMain" v-if="curTabIndex==4"/>

        <div v-show="1>2">
            <print-batch-code ref="printMe" :printTemplateArrData="PrintBatchCodeData" @updatedFn="updatedFn"></print-batch-code>
        </div>
        
         <dialog-vue  :wh_id='String(this.form.wh_id)'  :dialogTitle="dialogTitle" :dialogVisible="dialogVisible" @dialogVisibleChangeFn="dialogVisibleChangeFn" :ruleForm="ruleForm"  @goCancel="goCancel"  @goSubmit="goSubmit">
        </dialog-vue>
        <issue-vue :wh_id='String(this.form.wh_id)' :issueName='issueName' :issueIds='issueIds' :dialogTitle="dialogTitle" :issueVisible="issueVisible" @issueVisibleChangeFn="issueVisibleChangeFn" @goSubmit="issueSubmit">
        </issue-vue>
        <confirm-dialog @goConfirm='goConfirm' ref="confirmDialog"></confirm-dialog>

    </div>
</template>

<script>
 /* eslint-disable */ 
import {qrCode,getCategoriesApi } from "@/api"
    /** 获取资产操作列表    领用记录            领用确认        转移记录                  转移确认    退还记录              资产退还确认   报失记录             资产报失确认 获取转移仓库       资产转移        资产报废    资产下发*/
import { getAssetsListApi,getAssetsRecRecord,confirmReceice,getAssetsTransferRecord,adminConfirm,getAssetsReturnRecord,confirmReturn,getAssetsLossRecord,confirmLoss,getOtherWarehouse,transferAssets,scrapAssets,distributeAssets,

/**资产删除 获取二维码设置类型  保存二维码打印设置  盘点任务列表  启动盘点任务     暂停盘点任务   启动任务删除      */
delAssets,  getQrcodeType,    setCodeConf,     getAssetcheck,startAssetcheck,stopAssetcheck,removeAssetcheck,

/*转移仓记录                 转移仓确认       回收站资产列表          资产彻底删除  资产还原     下载模板           导入*/
getAssetsWareTransferRecord,transferConfirm,getAssetsRecycleRecord,removeAssets,restoreAsset,downloadTemplate,importTemplate,getNumber} from "./api"
import fileutil from '@/libs/fileUtil'
import TabVue from "@/components/TabVue"
import PrintBox from "@/components/PrintBox"
import printBatchCode from "@/components/printBatchCode"
import Pagination from "@/components/Pagination"
import LpjTableVue from "@/components/LpjTableVue"
import DialogVue from "@/components/DialogVue"
import IssueVue from "@/components/IssueVue"
import constObj from '@/config/const' /**表头常数 */
import newAddAsset from "./components/newAddAsset"/**新增资产 */
import assetsClass from "./components/assetsClass"/**资产分类 */
import rapairSetting from "./components/rapairSetting"/**资产分类 */
import headerBtn from "@/components/headerBtn"/**表头tab */
import searchBox from "@/components/searchBox"/**搜索框 */
import assetInventory from "./components/assetInventory"/**新增资产盘点任务 */
import confirmDialog from "@/components/confirmDialog"/**确认领用、报失、退还弹窗 */
import qrcodeMain from "@/components/qrCodeMain"/**确认领用、报失、退还弹窗 */
import assemblyIntegration from "@/components/assemblyIntegration"/** 新版搜索框 */
import { Badge } from 'element-ui'
export default {
    name:"assetsManage",
    components:{TabVue,LpjTableVue, PrintBox,printBatchCode,Pagination, DialogVue,IssueVue,headerBtn,searchBox,newAddAsset,assetsClass,rapairSetting,assetInventory,confirmDialog,qrcodeMain,assemblyIntegration,ElBadge:Badge},
    data(){
        return { 
            myWarehouse:[],
            form:{f_name:'',time:[], f_code:'', f_cid:'', c_status:'',departments:'',users:'',wh_id:'',start_time:'',end_time:''},/**搜索框form */
            formInline:[ /**搜索框 */
                {type:'input',value:'f_name',label:'资产名称',placeholder:'请输入内容',hide:false},
                {type:'input',value:'f_code',label:'资产编码',placeholder:'请输入内容',hide:false},
                {type:'select',value:'f_cid',label:'资产分类',placeholder:'请选择',options:[],hasGroup:true,defaultProp:['id','category_name','cate'],treeProp:{children: 'cate',label: 'category_name'},hide:false},
                {type:'select',value:'c_status',label:'资产状态',placeholder:'请选择',options:constObj.states,hasGroup:false,defaultProp:['id','name'],hide:false},
                {type:'daterange',value:'time',label:'入库时间',hide:false},
                {type:'dept',value:'departments',label:'申请部门',placeholder:'请选择',options:[],hide:false},
                {type:'people',value:'users',label:'领用人',placeholder:'请输入内容',options:[],hide:false}
            ],
            btnList:[
                {
                    type:'batchExport',
                    label:'数据导出'
                },
                {
                    type:'batchIssue',
                    label:'批量下发'
                },
                {
                    type:'batchAllot',
                    label:'批量调拨'
                },
                {
                    type:'batchTransfer',
                    label:'批量转移'
                },
                {
                    type:'batchTakeBack',
                    label:'批量收回'
                },
                {
                    type:'batchDelete',
                    label:'批量删除',
                    status:true
                }
            ],
            tabList:[
                {
                    key:'资产列表',
                },
                {
                    key:'回收站',
                }
            ],
            action:'table',/**table 为表格，add为新增页面 */
            rules: {},/*表单校验规则*/
            tabArr: [
                 {num:'',content:'资产列表'},
                 {num:'',content:'资产分类'},
                 {num:'',content:'新增资产'},
                 {num:'',content:'申请消息'},
                 {num:'',content:'二维码管理'},
                 {num:'',content:'设置管理'}, //原设置维修
                 {num:'',content:'盘点管理'}, //原资产盘点
                 {num:'',content:'报废资产'}, //新加
                 {num:'',content:'遗失资产'}, //新加
                 {num:'',content:'资产调拨'}, //转移仓记录
            ],
            assetsUpdate:false, //修改资产
            assetsUpdateId:null,//修改ID,必须为null或''或0
            /**操作列表表头数据 */
            tableHeaderData:JSON.parse(JSON.stringify(constObj.tableHeaderOfmyAssetsManager)) ,
            indexList:[0,3,5,6,7,8,9],
            /*操作列表table里的数据 */
            tableData:[],
            /*分页 数据*/
            paginationMes:{per_page:10,current_page:1,totol:0}, /**操作列表分页参数 */
            selectionData:[],  /** 表格CheckBox选中数据 */
            /**打印模板 */
            printTemplate:[
            	{title : "模板一", temIndex : 1, radio : 2, subTitle : "资产编码+二维码", id : "TF29-4760", url : ""},
            	{title : "模板二", temIndex : 2, radio : 2, subTitle : "资产名称+资产编码+二维码", name : "苹果电脑", id : "TF29-4760", url : ""},
            	{title : "模板三", temIndex : 3, radio : 2, subTitle : "公司LOGO+资产编码+二维码", name_none : "EPSON 556 喷墨打印机", id : "TF29-4760", companyName : "", hasPhoto : true, src : require('@/assets/images/logo_company.png'),url:""}
            ],
            printCurIndex: 2, /**本地存储的模板标记 */
            printCur: 2, /**所选择的模板标记 */
            PrintBatchCodeData:[] , /**打印数据 */
            printIds:[], /**存放打印的资产id */
            fileexecl:"",//上传文件
            /*当前选中的 tab下标*/
            curTabIndex:0,
            dialogVisible:false,
            issueVisible:false,
            issueIds:'',
            issueName:'',
            dialogTitle:'',
            ruleForm: {
                formList: [],
                addForm:[]
            },/*领用表单*/
            userArr:[],/**申请人列表 */
            deptArr:[],/**申请部门列表 */
            qrCodeTpData:{
                    1:{
                        tempName:"模版一",
                        size:"80mm x 40mm",
                        title:'苹果电脑笔记本的钉',
                        number:'TF29-4760',
                        qr_type:'1'
                        },
                    2:{
                        tempName:"模版二",
                        title:'苹果电脑笔记本的钉',
                        number:'TF29-4764',
                        size:"60mm x 30mm",
                        qr_type:'2'
                    }
            }
        }
    },
    created(){
        this.curTabIndex = localStorage.curTabIndex?Number(localStorage.curTabIndex):0
        this.myWarehouse = this.$store.state.myWarehouse
        this.form.wh_id = this.$store.state.warehouseOfAssetsManager||this.$store.state.myWarehouse[0].wh_id
        this.$store.commit('changeWarehouse',this.form.wh_id);
        /**获取资产操作列表 */
        // this.messageSearch()
        this.getCurTabIndexFn(this.curTabIndex)
        this.$store.commit('setQrCodeTpData',this.qrCodeTpData)

        this.getBadge()
    },
    methods:{
        assetsUpdateClose(){
            this.assetsUpdate = false
            this.assetsUpdateId = null
        },
        tabLiChange(index,status = false){
           this.$store.commit('setactiveIndex',index)
           if(this.curTabIndex == 0){
                if(index == 0 && status){
                    this.getCurTabIndexFn(0)
                }else if(index == 1 && status){
                    this.btnList = [
                        {
                            type:'batchDelete',
                            label:'批量删除',
                            status:true
                        }
                    ]
                    this.messageSearch(100)
                }
           }else if(this.curTabIndex == 3){
                switch(index){
                    case 0:
                        this.messageSearch()
                        console.log('领用申请')
                    break;
                    case 1:
                        this.messageSearch(400)
                        console.log('转移申请')
                    break;
                    case 2:
                        this.messageSearch(500)
                        console.log('退还申请')
                    break;
                    case 3:
                        this.messageSearch(600)
                        console.log('报失申请')
                    break;
                }
           }
        },
        btnListClick(item){
           console.log(item,'item')
           switch(item.type){
               case 'batchExport': // 数据导出
               console.log(item.label)
               break;
               case 'batchIssue': // 批量下发
               console.log(item.label)
               break;
               case 'batchAllot': // 批量调拨
               console.log(item.label)
               break;
               case 'batchTransfer': // 批量转移
               console.log(item.label)
               break;
               case 'batchTakeBack': // 批量收回
               console.log(item.label)
               break;
               case 'batchDelete': // 批量删除
               console.log(item.label)
               break;
           }
        },
        importFile(){
            fileutil.getFile({
                accept: '.xls,.xlsx',
                done: (file) => {
                    importTemplate({file,wh_id:this.form.wh_id}).then(res=>{
                        this.getCurTabIndexFn(this.curTabIndex)
                    })
                },
            })
        },
        uploadFile(){
            this.dd.biz.util.downloadFile({
                    url: 'http://zc.gzyuejie.top/download', //要下载的文件的url
                    name: '资产列表模板.xlsx',
                    onProgress: function(msg){
                        console.log(msg,'msgmsgmsg')
                    },
                    onSuccess : function(result) {},
                    onFail : function() {}
                })
        },
        dialogVisibleChangeFn(val){
            this.dialogVisible = val
            if(!val){
                this.ruleForm.formList=[]
            }
        },
        issueVisibleChangeFn(val){
            this.issueVisible = val
            if(!val){
                this.ruleForm.formList=[]
            }
        },
        // /*监听资产领用弹窗点击确定*/
        goSubmit(e,users,departments,dept_id){
            let promise
            switch(this.dialogTitle){
                case '资产转移':promise=transferAssets(e);break;
                case '资产报废':promise=scrapAssets(e);break;
                case '资产下发':let params = e;params.append('users',JSON.stringify(users));params.append('departments',JSON.stringify(departments));params.append('dept_id',dept_id);
                    promise=distributeAssets(params);break;
            }
            promise.then((res)=>{
                this.goCancel()
                this.$store.commit('changeDisabled', false)
                this.getCurTabIndexFn(this.curTabIndex)
            }).catch(err=>{
                this.$store.commit('changeDisabled', false)
            })
        },
        issueSubmit(params){
           distributeAssets(params)
           .then(res=>{
                    this.issueVisible = false
                    this.issueIds = ''
                    this.issueName = ''
                    // this.getCurTabIndexFn(this.curTabIndex)
                    this.messageSearch()
           })
        },
        /**弹窗取消按钮 */
        goCancel(){
            this.dialogVisible = false
            this.ruleForm = {formList:[],addForm:[]}
        },
        /**查询 */
        onSubmit(form,user,dept) {
            this.userArr = user
            this.deptArr = dept
            this.paginationMes.current_page = 1
            this.form = {
                ...this.form,
                ...form
            }
            this.messageSearch()
        },
        /**当仓库值改变时，缓存起来,并刷新模块内数据 */
        changeWarehouse(val){
            this.$store.commit('changeWarehouse',val);
            if(this.curTabIndex==1){ /**资产分类 */
                this.$refs.assetsClass.getData()
            }else if(this.curTabIndex==2){ /**新增资产 */
                this.$refs.formVueBox.getClassData()
            }else if(this.curTabIndex==5){ /**设置维修 */
                this.$refs.rapairSetting.getData()
            }else if(this.curTabIndex==4){ /**二维码设置 */
                // this.$refs.qrcodeMain
            }else{
                this.messageSearch()
            }
        },
        /**tab组件点击事件 */
        getCurTabIndexFn(val){
            console.log(val)
            this.tabLiChange(0)
            switch(val){
                case 0:
                    this.tabLiChange(val)
                    this.tabList = [
                        {
                            key:'资产列表'
                        },
                        {
                            key:'回收站'
                        }
                    ]
                break;
                case 3:
                    this.getApplyForInfo()
                break;
            }
            localStorage.curTabIndex = val
            this.printIds = [];
            this.PrintBatchCodeData = []; 

            this.curTabIndex = val
            this.action = 'table'
            this.paginationMes = {per_page:10,current_page:1,totol:0}
            this.form = { f_name:'',time:[], f_code:'', f_cid:'', c_status:'',departments:'',users:'',wh_id:this.$store.state.warehouseOfAssetsManager,start_time:'',end_time:''}/**搜索框form */
            this.userArr = []
            this.deptArr = []
            this.$refs.searchBox?this.$refs.searchBox.init():''

            if(this.indexList.indexOf(val)>-1){/*如果是列表页 */
                this.formInline.forEach(item=>{item.hide= val==6}) /**如果是资产盘点，隐藏所有搜索框，否则初始化所有搜索框为显示*/
                if(0<val&&(val<4)){
                    this.formInline[3].hide = true;
                    this.formInline[6].label = ['领用人','领用人','转移人','退还人','报失人'][this.indexList.indexOf(val)]/**如果是操作列表，需要修改第七个搜索框表单的label */
                }
                if(val>6){
                    this.formInline[6].hide = true;this.formInline[5].hide = true  /**回收站和转移仓记录需要隐藏搜索框的人和部门 */
                } 
                this.getAllClass()
                this.messageSearch()
            }
        },
        getApplyForInfo(){
          getNumber({wh_id:this.form.wh_id}).then(res=>{
            this.$store.commit('changeBadgeNumber',res);
            this.tabList = [
                {
                    key:'领用申请',
                    number:this.$store.state.badgeNumber.receive || 0
                },
                {
                    key:'转移申请',
                    number:this.$store.state.badgeNumber.transfer || 0
                },
                {
                    key:'退还申请',
                    number:this.$store.state.badgeNumber.return || 0
                },
                {
                    key:'报失申请',
                    number:this.$store.state.badgeNumber.loss || 0
                }
            ]
            this.tabArr = [
                 {num:'',content:'资产列表'},
                 {num:'',content:'资产分类'},
                 {num:'',content:'新增资产'},
                 {num:`${this.$store.state.badgeNumber.receive + this.$store.state.badgeNumber.transfer + this.$store.state.badgeNumber.return + this.$store.state.badgeNumber.loss || 0}`,content:'申请消息'},
                 {num:'',content:'二维码管理'},
                 {num:'',content:'设置管理'}, //原设置维修
                 {num:'',content:'盘点管理'}, //原资产盘点
                 {num:'',content:'报废资产'}, //新加
                 {num:'',content:'遗失资产'}, //新加
                 {num:'',content:'资产调拨'}, //转移仓记录
            ]
		  })
        },
        /**获取资产分类 */
        getAllClass(){
            getCategoriesApi({category_type:2,wh_id:this.$store.state.warehouseOfAssetsManager}).then(res=>{
                this.formInline[2].options = res
            })
        },
        /**获取列表 */
        messageSearch(number){
            let time = this.form.time
            let promise
            let params = {}
            console.log(this.form,'this.form')
            params.start_time = time&&time.length>0?time[0]:'' /**开始时间 */
            params.end_time = time&&time.length?time[1]:''/**结束时间 */
            params.page = this.paginationMes.current_page /**页码 */
            params.num = this.paginationMes.per_page /**每页数 */
            params.f_name = this.form.f_name /**资产名 */
            params.f_code = this.form.f_code /**资产编码 */
            params.f_cid = this.form.f_cid /**资产分类 */
            params.wh_id = this.form.wh_id /**仓库 */
            
            // 11
            if([0,10,100].indexOf(this.curTabIndex)>-1){ /**资产列表、回收站、转移仓有资产状态 */
                params.c_status = this.form.c_status /**仓库 */
            }
            if([0,3].indexOf(this.curTabIndex)>-1){ /**资产列表、和四种状态的申请有申请人和申请部门 */
                params.users = this.userArr&&this.userArr.length?JSON.stringify(this.userArr):''
                params.departments = this.deptArr&&this.deptArr.length?JSON.stringify(this.deptArr):''
            }
            switch(Number(number || this.curTabIndex)){
                case 0:promise = getAssetsListApi(params);break;/**资产列表页 */
                case 3:promise = getAssetsRecRecord(params);break;/**领用列表页 */
                case 400:promise = getAssetsTransferRecord(params);break;/**转移列表页 */
                case 500:promise = getAssetsReturnRecord(params);break;/**转移列表页 */
                case 600:promise = getAssetsLossRecord(params);break;/**报失列表页 */
                case 6:getAssetcheck({wh_id:this.form.wh_id}).then(res=>{this.tableData=res});break;/**资产盘点页 */
                case 100:promise = getAssetsRecycleRecord(params);break;/**回收站列表页 */
                case 7:promise = getAssetsWareTransferRecord(params);break;/**转移仓列表页 */
            }
            promise?promise.then(res=>{
                this.paginationMes={total:Number(res.total),per_page:Number(res.per_page),current_page:Number(res.current_page),}
                this.tableData=res.data
            }).catch(err=>{
                this.tableData=[]
                this.paginationMes = {per_page:10,current_page:1,totol:0} /**操作列表分页参数 */
            }):''
        },
        
        /**清空checkbox选中 */
        clearSelectFn(){
            this.$refs.lpjTable.$refs.LpjTableVue.clearSelection();
            this.selectionData = [];
            this.printIds = []
        },
        /**操作列按钮 */
        linkBtnFn(val,data){
            log(val)
            switch (val+this.curTabIndex) {
                case "下发0":this.linkToGive(data);break;
                case "转移仓库0":this.linkToDivice(data);break;
                case "编辑0":
                    this.assetsUpdate = true
                    this.assetsUpdateId = data.id
                break;
                // case "编辑0":this.$router.push({ name:'editAssets',query:{id:data.id}});break;
                case "报废0":this.linkToUnuse(data);break;
                case "删除0":this.toLinkComfireFn(data,val); break;

                
                case "请确认3":this.confirmFn(data,'资产领用确认'); break;
                case "请确认5":this.confirmFn(data,'资产退还确认'); break;
                case "请确认6":this.confirmFn(data,'资产报失确认'); break;
                // case "请确认3":this.toLinkComfireFn(data,'确认领用申请'); break;
                // case "请确认5":this.toLinkComfireFn(data,'确认退还申请'); break;
                // case "请确认6":this.toLinkComfireFn(data,'确认报失申请'); break;

                case "请确认4":this.toLinkComfireFn(data,'确认转移申请'); break;
                case "启动盘点9":this.toLinkComfireFn(data,'确认启动盘点任务','c_name'); break;
                case "删除任务9":this.toLinkComfireFn(data,'确认删除盘点任务','c_name'); break;
                case "暂停任务9":this.toLinkComfireFn(data,'确认暂停盘点任务','c_name'); break;
                case "盘点报表9":this.$router.push({path:'/assetInventoryDatail',query:{id:data.id}});; break;
                case "还原10":this.toLinkComfireFn(data,'还原资产'); break;
                case "彻底删除10":this.toLinkComfireFn(data,'彻底删除资产'); break;
                case "请确认11":this.toLinkComfireFn(data,'确认转移仓'); break;  
            }
        },
        /**确认弹窗 */
        confirmFn(data,title){
            switch(title){
                case '资产领用确认':
                    this.$refs.confirmDialog.textList = [
                        `申请人：${data.re_user_name}`,
                        `所属部门：${data.re_dept_name}`,
                        `资产名称：${data.f_name}`,
                        `资产编码：${data.f_code}`,
                        `请确认资产已经交付给申请人！`
                    ];break;
                case '资产退还确认':
                    this.$refs.confirmDialog.textList = [
                        `申请人：${data.user_name}`,
                        `退还资产名称：${data.f_name}`,
                        `退还资产编码：${data.f_code}`,
                        `请您确认资产完好，再进行确认！`
                    ];break;
                case '资产报失确认':
                    this.$refs.confirmDialog.textList = [
                        `报失人：${data.user_name}`,
                        `报失资产名称：${data.f_name}`,
                        `报失资产编码：${data.f_code}`,
                        `资产报失原因：${data.lo_reason}`,
                    ];break;
            }
            
            this.$refs.confirmDialog.dialogTitle = title
            this.$refs.confirmDialog.this_id = data.id
            this.$refs.confirmDialog.dialogVisible = true
        },
        /**弹窗请求 */
        toLinkComfireFn(val,label,name){
            this.$confirm(`即将${label}"${val[name||'f_name']}", 是否继续?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.goConfirm(val.id,label+this.curTabIndex,val)
            });
        },
        goConfirm(id,label,val){
            let param = {id}
                let promise
                switch(label){ 
                    case '删除0':promise=delAssets({deleted:0,id});break;

                    case '资产领用确认':promise=confirmReceice(param);break;
                    case '资产退还确认':promise=confirmReturn(param);break;
                    case '资产报失确认':promise=confirmLoss(param);break;

                    case '确认转移申请4':promise=adminConfirm(param);break;
                    case '确认启动盘点任务9':promise=startAssetcheck(param);break;
                    case '确认删除盘点任务9':promise=removeAssetcheck(param);break;
                    case '确认暂停盘点任务9':promise=stopAssetcheck(param);break;

                    case '还原资产10':promise=restoreAsset(param);break;
                    case '彻底删除资产10':promise=removeAssets({deleted:2,id});break;
                    case '确认转移仓11':promise=transferConfirm({wt_a_id:val.f_id,wt_wh_id:val.wt_wh_id,id:val.id});break;
                }
                promise?promise.then(res=>{
                    this.getCurTabIndexFn(this.curTabIndex)
                    this.getBadge()
                }):''
        },
        /**报废 */
        linkToUnuse(val){
            this.ruleForm.formList = [
                { type: 'textarea', name:'f_scrap_reason', label: '报废原因', placeholder: '请输入报废原因', className: 'two', formValue:'',rules:[{ required: true, message: '请输入报废原因', trigger: 'blur' }]},
                { type: 'upload',name:'f_image_url', label: '图片', limitNum: 6,formValue:[],rules:[{ required: true, message: '请上传报修图片', trigger: 'change',type: 'array', }]}
                ]
                this.ruleForm.addForm = [
                    {name:'id',formValue:val.id},
                ]
                this.dialogVisible = true
                this.dialogTitle = '资产报废'
        },
        /**下发 */
        linkToGive(val){
            this.issueIds = val.id
            this.issueName = val.f_name
            this.dialogTitle = '资产下发'
            this.issueVisible = true
        },
        /**转移仓库 */
        linkToDivice(data){
            getOtherWarehouse({wh_id:this.form.wh_id}).then(res=>{
                this.ruleForm.formList = [
                    { type: 'select', name:'wt_wh_id', label: '选择仓库', placeholder: '请选择仓库',option:res,formValue:'',defaultProps:{label:'wh_name',value:'wt_wh_id'},rules:[{ required: true, message: '请选择仓库', trigger: 'blur' },{ type:'number', message: '请输入数字', trigger: 'blur' }]},
                    { type: 'textarea', name:'wt_reason', label: '备注', placeholder: '请输入备注', className: 'two', formValue:'',rules:[{ required: true, message: '请输入备注', trigger: 'blur' }]},
                ]
                this.ruleForm.addForm = [
                    {name:'wt_a_id',formValue:data.id},
                    {name:'wh_id',formValue:this.form.wh_id}
                ]
                this.dialogVisible = true
                this.dialogTitle = '资产转移'
            })
        },
        getBadge() {
          getNumber({wh_id:this.form.wh_id}).then(res=>{
            this.$store.commit('changeBadgeNumber',res);
            this.tabArr = [
                 {num:'',content:'资产列表'},
                 {num:'',content:'资产分类'},
                 {num:'',content:'新增资产'},
                 {num:`${this.$store.state.badgeNumber.receive + this.$store.state.badgeNumber.transfer + this.$store.state.badgeNumber.return + this.$store.state.badgeNumber.loss || 0}`,content:'申请消息'},
                 {num:'',content:'二维码管理'},
                 {num:'',content:'设置管理'}, //原设置维修
                 {num:'',content:'盘点管理'}, //原资产盘点
                 {num:'',content:'报废资产'}, //新加
                 {num:'',content:'遗失资产'}, //新加
                 {num:'',content:'资产调拨'}, //转移仓记录
            ]
		  })
        },
        /**新增资产按钮 */
        addAssetsFn(){
            this.$router.push({name:"addPutWarehousing",query:{ param: this.$route.meta.title}})
        },
        /**表格CheckBox勾选事件 */
        handleSelectionChange(selection){
            let status01 = selection.some( function( item, index, array ){  // 闲置
                return item.f_status == 1; 
            })
            let status02 = selection.some( function( item, index, array ){  // 在用
                return item.f_status == 2; 
            })
            if(status01 && status02){
                this.btnList = [
                    {
                        type:'batchExport',
                        label:'数据导出',
                        status:selection.length > 0
                    },
                    {
                        type:'batchIssue',
                        label:'批量下发'
                    },
                    {
                        type:'batchAllot',
                        label:'批量调拨'
                    },
                    {
                        type:'batchTransfer',
                        label:'批量转移'
                    },
                    {
                        type:'batchTakeBack',
                        label:'批量收回'
                    },
                    {
                        type:'batchDelete',
                        label:'批量删除',
                        status:true
                    }
                ]
            }else{
                this.btnList = [
                    {
                        type:'batchExport',
                        label:'数据导出',
                        status:selection.length > 0
                    },
                    {
                        type:'batchIssue',
                        label:'批量下发',
                        status:status01
                    },
                    {
                        type:'batchAllot',
                        label:'批量调拨',
                        status:status01
                    },
                    {
                        type:'batchTransfer',
                        label:'批量转移',
                        status:status02
                    },
                    {
                        type:'batchTakeBack',
                        label:'批量收回',
                        status:status02
                    },
                    {
                        type:'batchDelete',
                        label:'批量删除',
                        status:true
                    }
                ]
            }
            this.selectionData = selection
            this.selectionLength = selection.length
            this.printIds = []
            selection.map(item=>{
                this.printIds.push(item.id)
            })
        },
        /*操作列表分页传过来的 当前第几页 */
        currentChangeFn(val){
            this.paginationMes.current_page = val||1//当前页数
            this.messageSearch()
        },
        /*操作列表分页传过来的 table每页的条数*/
        sizeChangeFn(val){
            this.paginationMes.current_page=1
            this.paginationMes.per_page = val||10//当前页数
            this.messageSearch()
        },

        /**打印模板选择 */
        radioIndexChange(temIndex){
            this.printCur = temIndex
            this.printTemplate.forEach(item=>{
                Object.assign(item,{radio:temIndex}) 
            })
        },
        /**打印数据赋值，传入打印组件执行 */
        PrintFn(data){
            let that = this
            this.PrintBatchCodeData = data
        },
        /**打印组件传出事件，进行打印 */
        updatedFn(val){
            this.$nextTick(()=>{
                this.$print(val)
                if(this.curTabIndex==0){ this.clearSelectFn() }
                this.PrintBatchCodeData = []
                this.printIds = []
            })
        },
        /**打印预览 */
        seePrint(){
            let printData = [];
            printData.push(this.printTemplate[this.printCur-1])
            this.PrintFn(printData)
        },
        /**报存打印模板 */
        savePrintTemplate(){
            setCodeConf({qr_type:this.printCur,wh_id:this.form.wh_id}).then(res=>{
                this.printCurIndex = this.printCur
            })
        },
        //资产编号前往详情页面
        pointerClick(data){
            this.$router.push({name:"myAssetsDetails",query:{key:data.asset_id, param: this.$route.meta.title,}})
        },

        
    }
}
</script>

<style lang='stylus' scoped>
.assetsManage
    height 100%
    .tabList
        list-style-type none
        width 100%
        height 50px
        background-color rgba(243, 246, 249, 1)
        border-radius 5px 5px 0px 0px
        border-bottom: 1px solid rgba(224, 227, 234, 1)
        // border-left none
        display flex
        li
           width 130px
           height 50px
           line-height 50px
           text-align center
           font-size 14px
           color #606266
           font-weight 600
           cursor pointer
           border-right 1px solid rgba(224, 227, 234, 1)
           position relative
           &:last-child
             border-left none !important
             border-radius 5px 5px 0px 0px
           &:first-child
             border-right 1px solid rgba(224, 227, 234, 1)
             border-radius 5px 5px 0px 0px
        .active
           color rgba(56, 148, 255, 1);
           background-color #fff
           border-radius 5px 5px 0px 0px
           padding-bottom 1px
           border-right 1px solid rgba(224, 227, 234, 1)
        //    border-left 1px solid rgba(224, 227, 234, 1)
    .head_btn
        height 32px
        color #3296FA
        border 1px solid #3296FA 
    .operationBox
        background-color #fff
        border: 1px solid rgba(224, 227, 234, 1);width:clac(100% - 2px)
        border-radius 5px 5px 0px 0px
    .contentTitleBox
        height 32px 
        line-height 32px
        font-size 12px
        background rgba(50, 150, 250, 0.08)
        border-radius 4px
        padding 0 12px
        margin-bottom 10px
        font-family "SourceHanSansCN-Regular"
        span 
            font-family "SourceHanSansCN-Regular"
            color #3296FA 
            .el-button
                >>>span 
                    font-size 12px 
                    margin-left 10px
    

    .contentTableBox
        background #fff
        padding 20px 12px
        border-radius 4px
        .table_btn
            height 32px
            line-height 32px
            margin-bottom 12px
            .el-button
                height 32px
            .table_btn_right
                float right
    .printSetupBox
        borber-radius 0 0 4px 4px
        width 100%
        min-height 90% !important
        margin-bottom 10px
    .errorlist 
        margin-top 12px
        li
            line-height 30px
            color red
    .dialog-footer
        text-align: center;
</style>
<style lang="stylus">
.badgeClass 
    position absolute;
    top 13px;
    right 25px;
    -webkit-transform translateY(-50%) translateX(100%);
    transform translateY(-50%) translateX(100%);
    z-index 999
    
</style>
